<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }
    
    div {
        width: 300px;
        height: 500px;
        margin: 0 auto;
    }
    
    .box1 {
        width: 80px;
        height: 50px;
        position: fixed;
        background-color: rgb(151, 82, 82);
        line-height: 50px;
        text-align: center;
        left: 1100px;
        top: 500px;
    }
</style>

<body>
    <div style="background-color: yellowgreen;">
        <p class="box1">回到顶部</p>
    </div>
    <div style="background-color: aqua;"></div>
    <div style="background-color: black;"></div>
    <div style="background-color: red;"></div>
    <div style="background-color: yellow;"></div>
    <div style="background-color: blue;"></div>
    <div style="background-color: green;"></div>
    <div style="background-color: greenyellow;"></div>

</body>

</html>
<script>
    var box = document.getElementsByClassName("box1")[0]
    box.onclick = function() {
        document.documentElement.scrollTop = 0
    }
</script>